package com.ybkj.daijia.template.shiro;

import com.ybkj.daijia.common.Principal;
import freemarker.core.Environment;
import freemarker.log.Logger;
import freemarker.template.TemplateDirectiveBody;
import freemarker.template.TemplateException;
import java.io.IOException;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;

public class HasSmsMessageTag extends SecureTag {

    private static final Logger log = Logger.getLogger("HasSmsMessageTag");

    @Override
    public void render(Environment env, Map params, TemplateDirectiveBody body)
        throws IOException, TemplateException {

        if (getSubject() != null && null != getSubject().getPrincipal() && StringUtils
            .isNoneBlank(((Principal) getSubject().getPrincipal()).getSmsMessage())) {
            if (log.isDebugEnabled()) {
                log.debug("Subject exists and is authenticated.  Tag body will be evaluated.");
            }

            renderBody(env, body);
        } else {
            if (log.isDebugEnabled()) {
                log.debug(
                    "Subject does not exist or is not authenticated.  Tag body will not be evaluated.");
            }
        }
    }

}
